<?php
require_once("handler.class.php");

class qIfHandler extends qHandler
{
    function  __construct()
    {
    	$this->iscloseable = true;
    	$this->parsechildren = true;
    }
        
    public function Parse($tag, $body)
    {
        $parameter = mb_substr($tag, 4, -1);
		$preg = '/\$([a-zA-Z0-9\.]+)/';
		
		$values = qTemplateParser::Values();
		
		preg_match_all($preg, $parameter, $array, PREG_SET_ORDER);
		
		foreach ($array as $elem)
		{
			if (isset($values[$elem[1]]))
			{
		    	$parameter = str_replace($elem[0], $values[$elem[1]], $parameter);
			}
			else
			{
			    return array(false, "qIfHandler Error: variable {$elem[0]} is not set!<br />{$tag}{$body}{endif}");
			}
		}
		
		eval('$result = '.$parameter.';');
		
		if ($result)
		{
		    return array(true, $body);
		}
		else
		{
		    return array(true, "");
		}
    }
}